package org.iteye.bbjava.action;

import org.apache.struts2.ServletActionContext;
import org.dom4j.Document;
import org.iteye.bbjava.service.TableStructXmlService;
import org.iteye.bbjava.util.AjaxXmlUtil;
import org.iteye.bbjava.util.entity.TableStructXml;

import com.opensymphony.xwork2.ActionSupport;

public class DataCreateAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = -5252890348333425704L;
	public String index;
	private TableStructXmlService tableStructXmlService; 
	public String execute() {
		String index = (String) ServletActionContext.getRequest().getParameter(
				"index");
		if ("1".equals(index)) {
			try {
				Document xml = AjaxXmlUtil.createDocumentFromRequest(ServletActionContext.getRequest());
				System.out.println(xml.asXML());
				TableStructXml tableStructXml = new TableStructXml();
				tableStructXml.setContent(xml.asXML());
				tableStructXml.setName(xml.getRootElement().attributeValue("name"));
 				tableStructXmlService.saveTableStructXml(tableStructXml);
				AjaxXmlUtil.responseXML(ServletActionContext.getResponse(), xml.asXML());
			} catch (Exception e) {
				e.printStackTrace();
			}
			return SUCCESS;
		}
		return null;
	}

	public String getIndex() {
		return index;
	}

	public void setIndex(String index) {
		this.index = index;
	}

	public TableStructXmlService getTableStructXmlService() {
		return tableStructXmlService;
	}

	public void setTableStructXmlService(TableStructXmlService tableStructXmlService) {
		this.tableStructXmlService = tableStructXmlService;
	}

	
}
